package cn.bincker.mycaptcha.utils;

import lombok.extern.slf4j.Slf4j;

import java.awt.*;
import java.util.stream.Stream;

@Slf4j
public class FontUtils {
    private static final char[] LETTER_CHARTS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();

    public static String[] getCanDisplayFontFamilyNames(){
        return Stream.of(
                GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()
        )
                .filter(name->{
                    var font = new Font(name, Font.PLAIN, 12);
                    for (char c : LETTER_CHARTS) {
                        if(!font.canDisplay(c)) return false;
                    }
                    return true;
                })
                .toArray(String[]::new);
    }
}
